<template>
	<view>
		<!-- 自定义导航栏 -->
		<uni-nav-bar left-icon="arrowleft" right-text="发布" statusBar @clickLeft="handleNavgateBack" @clickRight="handlePublishClick">
			<view class="u-f-ajc" style="width: 100%;" @tap='handleSelectLookChange'>
				{{changelook[selectIndex]}}
				<view class="icon iconfont icon-xialazhankai"></view>
			</view>
		</uni-nav-bar>
		<!-- 多行为本框 -->
		<view class="uni-textarea">
			<textarea  placeholder="说一句话吧~~~" v-model.trim="text"/>
		</view>
		<!-- 图片上传 -->
		<uni-upload-image @upload='handleUploadImage'/>
		<!-- 弹出框 -->
		<uni-popup :show="showPopup" position="middle" mode="fixed" @hidePopup='handleHidePopup'>
			<view class="gonggao">
				<view class="u-f-ajc">
					<image src="/static/common/addinput.png" mode="widthFix"></image>
				</view>
				<view>1. 涉及黄色, 政治, 广告及骚扰信息</view>
				<view>2. 涉及人身攻击</view>
				<view>3. 留联系方式, 透露他人隐私</view>
				<view>一经核实将被封禁, 情节严重者永久封禁</view>
				<button type="default" @tap='handleHidePopup'>朕知道了</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import UniNavBar from '../../components/uni-nav-bar/uni-nav-bar.vue'
	import UniUploadImage from '../../components/common/upload-image.vue'
	import UniPopup from '../../components/uni-popup/uni-popup.vue'
	export default {
		components:{
			UniNavBar,UniUploadImage,UniPopup
		},
		
		data() {
			return {
				showPopup: true,
				selectIndex: 0,
				changelook: ['所有人可见', '仅自己可见'],
				text: '',
				imgList: [],
				isFirstBack:true
			}
		},
		onBackPress() {
			
			if(!this.text&&!this.imgList.length) return false
			
			if(this.isFirstBack) {
				this.handleSaveDraft()
			}
			
			
			return this.isFirstBack
		},
		methods: {
			// 点击返回按钮
			handleNavgateBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 点击发布按钮 
			handlePublishClick() {
				console.log('点击发布按钮')
			},
			// 点击修改可见
			handleSelectLookChange() {
				uni.showActionSheet({
					itemList:this.changelook,
					success: (e) => {
						this.selectIndex = e.tapIndex
					}
				})
			},
			// 点击上传图片
			handleUploadImage(array) {
				this.imgList = array
				console.log(array)
			},
			// 点击关闭弹框
			handleHidePopup() {
				this.showPopup = false
			},
			// 保存草稿操作
			handleSaveDraft() {
				uni.showModal({
					content:"是否要保存为草稿",
					cancelText:"不保存",
					confirmText:"保存",
					success: (res)=> {
						if(res.confirm) {
							console.log('点击了保存...')
						}
						this.isFirstBack = false
						uni.navigateBack({
							delta:1
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
.uni-textarea {
	border-bottom: 1upx solid #EEEEEE;
}
.gonggao {
	width: 500upx;
}
.gonggao image{
	width: 75%;
	margin-bottom: 20upx;
}

.gonggao button {
	margin-top: 20upx;
	background-color: #fff934;
	color: #171606;
}
</style>
